﻿using System.Collections.Generic;
using System.Diagnostics;
using System;

namespace TaskCleanerNS
{
    public static class TaskCleaner
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists")]
        public static List<ProcessStatus> KillProcesses(List<string> processesNames)
        {
            List<ProcessStatus> ret = new List<ProcessStatus>();
            foreach (var processName in processesNames)
            {
                Process[] processes = Process.GetProcessesByName(processName.Trim());
                PStatus status = PStatus.Missed;

                if (processes.Length >= 0)
                {
                    foreach (var process in processes)
                    {
                        try
                        {
                            process.Kill();
                            status = PStatus.Dead;
                        }
                        catch
                        {
                            status = PStatus.Survivor;
                        }
                    }
                }
                ret.Add(new ProcessStatus { ProcessName = processName, Status=status  });
            }
            return ret;
        }
    }
}
